﻿using System;
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
using PanViewLibrary;

namespace UnitTestLibrary
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestZeroCtrPt()
        {
            var t = new MockCompositeTransform();
            t.TranslateX = 80;
            t.TranslateY = 60;
            t.Rotation = 40;
            t.CenterX = 100;
            t.CenterY = 30;

            t.ZeroCenterPoint();

            AssertIsClose(t.TranslateX, 122.7);
            AssertIsClose(t.TranslateY, 2.7);
            AssertIsClose(t.Rotation, 40);
            AssertIsClose(t.CenterX, 0);
            AssertIsClose(t.CenterY, 0);
        }

        [TestMethod]
        public void TestAppend()
        {
            var j = new MockCompositeTransform();
            j.TranslateX = 100;
            j.TranslateY = 30;
            j.Rotation = 45;

            var k = new MockCompositeTransform();
            k.TranslateX = 120;
            k.TranslateY = -80;
            k.Rotation = -60;

            k.Append(j);

            AssertIsClose(k.TranslateX, 241.42);
            AssertIsClose(k.TranslateY, 58.28);
            AssertIsClose(k.Rotation, -15);
        }

        void AssertIsClose(double a, double b)
        {
            Assert.IsTrue(Math.Abs(a - b) < 0.1);
        }
    }
}
